home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Mousebroken 1.0.1 / source / Modules source ƒ / Bouncy mouse / Bouncy module.c next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  2.0 KB  |  94 lines  |  [TEXT/KAHL]

  1. /* Bouncy Mouse -- a mouse module for Mousebroken */
  2. /* written by Mark Pilgrim, November 1993 */
  3. /* This module placed in the public domain. */
  4.  
  5. #include "Retrace.h"
  6. #include "GestaltEQU.h"
  7.  
  8. extern Boolean CrsrNew : 0x8CE;
  9. extern Point mTemp : 0x828;
  10.  
  11. Rect            gMainScreenBounds;
  12. int                direction;
  13. unsigned long    me;
  14.  
  15. void header(void);
  16. void main(void);
  17.  
  18. void header(void)
  19. {
  20.     asm
  21.     {
  22.         dc.l    0
  23.         move.l a0, d0
  24.         lea header, a0
  25.         jmp main
  26.     }
  27. }
  28.  
  29. #include "SetUpA4.h"
  30.  
  31. void main(void)
  32. {
  33.     VBLTask*        myVBL;            /* pointer to VBL structure  */
  34.     long            gestalt_temp;
  35.     OSErr            isHuman;
  36.     
  37.     RememberA0();                    /* for global variables */
  38.     SetUpA4();                        /* for global variables */
  39.     
  40.     asm                                /* move VBL structure pointer into local variable */
  41.     {                                /* need this so we can set vblCount later */
  42.         move.l d0, myVBL            /* (see below) */
  43.     }
  44.     
  45.     if (me != 'MMdl')
  46.     {
  47.         isHuman = Gestalt(gestaltQuickdrawVersion, &gestalt_temp);    /* Quickdraw version? */
  48.         gMainScreenBounds=(isHuman || (gestalt_temp < gestalt8BitQD)) ? screenBits.bounds :
  49.             (**GetMainDevice()).gdRect;
  50.         me = 'MMdl';                /* need so we don't re-initialize */
  51.         direction=1;                /* to start off the bouncing */
  52.     }
  53.     
  54.     switch (direction)
  55.     {
  56.         case 1:
  57.             mTemp.h--;
  58.             mTemp.v--;
  59.             if (mTemp.h<=gMainScreenBounds.left)
  60.                 direction=4;
  61.             else if (mTemp.v<=gMainScreenBounds.top)
  62.                 direction++;
  63.             break;
  64.         case 2:
  65.             mTemp.h--;
  66.             mTemp.v++;
  67.             if (mTemp.v>=gMainScreenBounds.bottom-1)
  68.                 direction--;
  69.             else if (mTemp.h<=gMainScreenBounds.left)
  70.                 direction++;
  71.             break;
  72.         case 3:
  73.             mTemp.h++;
  74.             mTemp.v++;
  75.             if (mTemp.h>=gMainScreenBounds.right-1)
  76.                 direction--;
  77.             else if (mTemp.v>=gMainScreenBounds.bottom-1)
  78.                 direction++;
  79.             break;
  80.         case 4:
  81.             mTemp.h++;
  82.             mTemp.v--;
  83.             if (mTemp.h>=gMainScreenBounds.right-1)
  84.                 direction=1;
  85.             else if (mTemp.v<=gMainScreenBounds.top)
  86.                 direction--;
  87.             break;
  88.     }
  89.         
  90.     CrsrNew = TRUE;            /* to redraw mouse */
  91.     myVBL->vblCount = 1;    /* how many ticks until this code gets called again */
  92.     RestoreA4();
  93. }
  94.